//
//  UserInfoModel.m
//  QucikDevelopTools
//
//  Created by ChitandaEru on 2016/10/14.
//  Copyright © 2016年 楊利嘉. All rights reserved.
//

#import "UserInfoModel.h"

@implementation UserInfoModel

+(instancetype)sharedInstance
{
    static UserInfoModel *sharedInstance = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[UserInfoModel alloc]init];
    });
    
    return sharedInstance;
}



-(void)saveInfoWithKey:(NSString *)key andValue:(NSObject *)value
{
    [[NSUserDefaults standardUserDefaults]setObject:value forKey:key];
    
    [[NSUserDefaults standardUserDefaults]synchronize];
}


-(void)saveBoolWithKey:(NSString *)key andValue:(BOOL)value
{
    [self saveInfoWithKey:key andValue:(value == YES?@"YES":@"NO")];
}


//存入对象
-(void)saveObjectWithKey:(NSString *)key andValue:(NSString *)value
{
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:[value copy]];
    
    [[NSUserDefaults standardUserDefaults] setObject:data forKey:key];
    
    [[NSUserDefaults standardUserDefaults] synchronize];
}



-(NSString *)getInfoByKey:(NSString *)key
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:key];
}

-(BOOL)getBoolWithKey:(NSString *)key
{
    return [[self getInfoByKey:key] isEqualToString:@"YES"];
}

-(instancetype)getObjectWithKey:(NSString *)key
{
    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    
    return [NSKeyedUnarchiver unarchiveObjectWithData:data];
}

-(void)setToken:(NSString *)token
{
    [self saveInfoWithKey:@"token" andValue:token];
}

-(NSString *)token
{
    return [self getInfoByKey:@"token"];
}

-(void)setCustomerId:(NSString *)customerId
{
    [self saveInfoWithKey:@"customerId" andValue:customerId];
}

-(NSString *)customerId
{
    return [self getInfoByKey:@"customerId"];
}

-(void)setDepartid:(NSString *)departid
{
    [self saveInfoWithKey:@"departid" andValue:departid];
}

-(NSString *)departid
{
    return [self getInfoByKey:@"departid"];
}

-(void)setCustomerMobile:(NSString *)customerMobile
{
    [self saveInfoWithKey:@"customerMobile" andValue:customerMobile];
}

-(NSString *)customerMobile
{
    return [self getInfoByKey:@"customerMobile"];
}

-(void)setCustomerNickname:(NSString *)customerNickname
{
    [self saveInfoWithKey:@"customerNickname" andValue:customerNickname];
}

-(NSString *)customerNickname
{
    return [self getInfoByKey:@"customerNickname"];
}

-(void)setCustomerLoginName:(NSString *)customerLoginName
{
    [self saveInfoWithKey:@"customerLoginName" andValue:customerLoginName];
}

-(NSString *)customerLoginName
{
    return [self getInfoByKey:@"customerLoginName"];
}

-(void)setCustomerRealName:(NSString *)customerRealName
{
    [self saveInfoWithKey:@"customerRealName" andValue:customerRealName];
}

-(NSString *)customerRealName
{
    return [self getInfoByKey:@"customerRealName"];
}

-(void)setCustomerPassword:(NSString *)customerPassword
{
    [self saveInfoWithKey:@"customerPassword" andValue:customerPassword];
}

-(NSString *)customerPassword
{
    return [self getInfoByKey:@"customerPassword"];
}

-(void)setCustomerHeadImg:(NSString *)customerHeadImg
{
    [self saveInfoWithKey:@"customerHeadImg" andValue:customerHeadImg];
}

-(NSString *)customerHeadImg
{
    return [self getInfoByKey:@"customerHeadImg"];
}

-(void)setCustomerCategoryId:(NSString *)customerCategoryId
{
    [self saveInfoWithKey:@"customerCategoryId" andValue:customerCategoryId];
}

-(NSString *)customerCategoryId
{
    return [self getInfoByKey:@"customerCategoryId"];
}

-(void)setCustomerCategoryName:(NSString *)customerCategoryName
{
    [self saveInfoWithKey:@"customerCategoryName" andValue:customerCategoryName];
}

-(NSString *)customerCategoryName
{
    return [self getInfoByKey:@"customerCategoryName"];
}

-(void)setMemberLevelId:(NSString *)memberLevelId
{
    [self saveInfoWithKey:@"memberLevelId" andValue:memberLevelId];
}

-(NSString *)memberLevelId
{
    return [self getInfoByKey:@"memberLevelId"];
}

-(void)setMemberLevelName:(NSString *)memberLevelName
{
    [self saveInfoWithKey:@"memberLevelName" andValue:memberLevelName];
}

-(NSString *)memberLevelName
{
    return [self getInfoByKey:@"memberLevelName"];
}

-(void)setCustomerIntegral:(NSString *)customerIntegral
{
    [self saveInfoWithKey:@"customerIntegral" andValue:customerIntegral];
}

-(NSString *)customerIntegral
{
    return [self getInfoByKey:@"customerIntegral"];
}

-(void)setCustomerReputation:(NSString *)customerReputation
{
    [self saveInfoWithKey:@"customerReputation" andValue:customerReputation];
}

-(NSString *)customerReputation
{
    return [self getInfoByKey:@"customerReputation"];
}

-(void)setUseReputation:(NSString *)useReputation
{
    [self saveInfoWithKey:@"useReputation" andValue:useReputation];
}

-(NSString *)useReputation
{
    return [self getInfoByKey:@"useReputation"];
}

-(void)setCustomerSex:(NSString *)customerSex
{
    [self saveInfoWithKey:@"customerSex" andValue:customerSex];
}

-(NSString *)customerSex
{
    return [self getInfoByKey:@"customerSex"];
}

-(void)setAlipayAccount:(NSString *)alipayAccount
{
    [self saveInfoWithKey:@"alipayAccount" andValue:alipayAccount];
}

-(NSString *)alipayAccount
{
    return [self getInfoByKey:@"alipayAccount"];
}

- (void)setStorageId:(NSString *)storageId
{
    [self saveInfoWithKey:@"storageId" andValue:storageId];
}

- (NSString *)storageId
{
    return [self getInfoByKey:@"storageId"];
}

-(void)setWxUid:(NSString *)wxUid
{
    [self saveInfoWithKey:@"wxUid" andValue:wxUid];
}

-(NSString *)wxUid
{
    return [self getInfoByKey:@"wxUid"];
}

-(void)setShopId:(NSString *)shopId
{
    [self saveInfoWithKey:@"shopId" andValue:shopId];
}

-(NSString *)shopId
{
    return [self getInfoByKey:@"shopId"];
}


-(void)setAdminCode:(NSString *)adminCode
{
    [self saveInfoWithKey:@"adminCode" andValue:adminCode];
}

-(NSString *)adminCode
{
    return [self getInfoByKey:@"adminCode"];
}

-(void)setIsBind:(BOOL)isBind
{
    [self saveBoolWithKey:@"isBind" andValue:isBind];
}

-(BOOL)isBind
{
    return [self getBoolWithKey:@"isBind"];
}

-(void)setIsLogin:(BOOL)isLogin
{
	[self saveBoolWithKey:@"isLogin" andValue:isLogin];

}

-(BOOL)isLogin
{
	return [self getBoolWithKey:@"isLogin"];

}

-(void)logOut
{
	self.token = @"";
    self.customerId = @"";
    self.customerMobile = @"";
    self.customerNickname = @"用户名";
    self.customerLoginName = @"";
    self.customerRealName = @"";
	self.customerPassword = @"";
    self.customerHeadImg = @"";
    self.customerCategoryId = @"";
    self.customerCategoryName = @"";
    self.memberLevelId = @"";
    self.memberLevelName = @"";
    self.customerIntegral = @"";
    self.customerReputation = @"";
    self.useReputation = @"";
    self.customerSex = @"";
    self.alipayAccount = @"";
    self.storageId = @"";
    self.wxUid = @"";
    self.shopId = @"";
    self.adminCode = @"";
	self.isLogin = NO;
}

/*
 @property (nonatomic, copy) NSString *customerId;
 @property (nonatomic, copy) NSString *customerMobile;
 @property(nonatomic, copy)NSString *customerNickname;
 @property (nonatomic, copy) NSString *customerLoginName;///
 @property (nonatomic, copy) NSString *customerRealName;///
 @property(nonatomic, copy)NSString *customerPassword;
 @property (nonatomic, copy) NSString *customerHeadImg;
 @property (nonatomic, copy) NSString *customerCategoryId;
 @property (nonatomic, copy) NSString *customerIntegral;
 @property (nonatomic, copy) NSString *customerReputation;
 @property (nonatomic, copy) NSString *useReputation;///
 @property (nonatomic, copy) NSString *customerSex;
 @property (nonatomic, copy) NSString *alipayAccount;
 @property (nonatomic, copy) NSString *memberLevelId;
 @property (nonatomic, copy) NSString *wxUid;///
 @property (nonatomic, copy) NSString *shopId;///
 */

@end
